package com.dyb.recuitment.controller;


import com.dyb.recuitment.common.Result;
import com.dyb.recuitment.entity.JobCategory;
import com.dyb.recuitment.service.IJobCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 职位分类表 前端控制器
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-23
 */
@RestController
@Api(tags = "职位分类表(JobCategory)")
@RequestMapping("/job_category")
public class JobCategoryController {

    @Autowired
    private IJobCategoryService jobCategoryService;

    @ApiOperation(value = "添加职位分类", notes = "通过父ID和分类名称添加职位分类"+ "{\"pid\":0,\"title\":\"\"}")
    @ApiImplicitParam(name = "jobCategory", value = "JobCategory类")
    @PostMapping("/add")
    public Object add(@RequestBody JobCategory jobCategory) {
        Object data = null;
        try {
            data = jobCategoryService.add(jobCategory);
//            userLogService.add(new UserLog(1, "添加职位分类"));
            if (data == null || (int) data == 0) {
                return Result.failure(data, "添加失败!");
            }
            return Result.success(data, "添加成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "职位分类详情", notes = "通过ID查询职位分类详情 {\"id\":1}")
    @ApiImplicitParam(name = "jobCategory", value = "JobCategory类")
    @PostMapping("/selectById")
    public Object selectById(@RequestBody JobCategory jobCategory) {
        Object data = null;
        try {
            data = jobCategoryService.getById(jobCategory);
            if (data == null) {
                return Result.warning(data, "职位分类为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "修改职位分类", notes = "修改职位分类 {\"\":\"\",\"id\":1}")
    @ApiImplicitParam(name = "jobCategory", value = "JobCategory类")
    @PostMapping("/update")
    public Object update(@RequestBody JobCategory jobCategory) {
        Object data = null;
        try {
            data = jobCategoryService.update(jobCategory);
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "修改失败!");
            }
            return Result.success(data, "修改成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "删除职位分类", notes = "通过ID删除职位分类" + "{\"id\":1}")
    @ApiImplicitParam(name = "jobCategory", value = "JobCategory类")
    @PostMapping("/delete")
    public Object delete(@RequestBody JobCategory jobCategory) {
        Object data = null;
        try {
            data = jobCategoryService.delete(jobCategory);
//            userLogService.add(new UserLog(resume.getUserId(), "删除职位分类"));
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "删除失败!");
            }
            return Result.success(data, "删除成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "按条件查询职位分类", notes = "按条件查询职位分类 {\"pid\":0}")
    @ApiImplicitParam(name = "jobCategory", value = "JobCategory类")
    @PostMapping("/selectByCompanyIndustry")
    public Object selectByCompanyIndustry(@RequestBody JobCategory jobCategory) {
        Object data = null;
        try {
            data = jobCategoryService.selectByJobCategory(jobCategory);
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "暂无职位分类!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询所有职位分类", notes = "查询所有职位分类")
    @GetMapping("/selectAllCompanyIndustry")
    public Object selectAllCompanyIndustry() {
        Object data = null;
        try {
            data = jobCategoryService.selectAllJobCategory();
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "暂无职位分类!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }


}
